﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NetFrameworkExtensions.Enterprise.Properties;

namespace NetFrameworkExtensions.Enterprise.Security
{
  public sealed class CommandAuthorizableOperation :
    AuthorizableOperation<CommandAuthorizableOperation>
  {
    internal CommandAuthorizableOperation(string entityName, string commandName)
      : base(commandName, AuthorizableOperationKind.Execute)
    {
      if (string.IsNullOrWhiteSpace(entityName))
        throw new ArgumentNullException("entityName");

      _EntityName = entityName;
    }

    private string _EntityName;
    public override string EntityName { get { return _EntityName; } }

    protected override bool EqualsOverride(CommandAuthorizableOperation other)
    {
      return base.EqualsOverride(other) && EntityName == other.EntityName;
    }

    public override int GetHashCode()
    {
      unchecked
      {
        return base.GetHashCode() * 37 ^ EntityName.GetHashCode();
      }
    }

    public override string ToString()
    {
      return FormattedResources.ExecuteCommand(EntityName, Name);
    }
  }
}
